﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using YArchitech.Controls;
using YArchitech.LIB;

namespace HangerSupport
{
	public class DensitySpecificationManage
	{
		public DensitySpecificationManage()
		{
			this.xmlPath = Path.Combine(Product.DataLocation, "CableTrayWeight.xml");
			bool flag = !File.Exists(this.xmlPath);
			if (flag)
			{
				YJKMessageBox.Warning("未找到规格数据资源文件！");
			}
			else
			{
				this.xmlDoc = XMLOperating.LoadXml(this.xmlPath);
			}
		}

		public List<CableTrayFormat> GetSpecificationsByType(string cableType)
		{
			List<CableTrayFormat> list = new List<CableTrayFormat>();
			try
			{
				List<XmlElement> allElements = this.GetAllElements(this.xmlDoc, "CableTray");
				foreach (XmlElement xmlElement in allElements)
				{
					string attribute = xmlElement.GetAttribute("Type");
					bool flag = !cableType.Equals(attribute);
					if (!flag)
					{
						list.Add(new CableTrayFormat
						{
							Type = attribute,
							Width = Convert.ToDouble(xmlElement.GetAttribute("Width")),
							Height = Convert.ToDouble(xmlElement.GetAttribute("Height")),
							density = Convert.ToDouble(xmlElement.GetAttribute("Density"))
						});
					}
				}
			}
			catch (Exception ex)
			{
				string message = ex.Message;
			}
			return list;
		}

		private List<XmlElement> GetAllElements(XmlDocument xmlDoc, string rootNode)
		{
			List<XmlElement> list = new List<XmlElement>();
			try
			{
				XmlNode xmlNode = xmlDoc.SelectSingleNode("WeightTable");
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					bool flag = xmlNode2.Name != rootNode;
					if (!flag)
					{
						foreach (object obj2 in xmlNode2.ChildNodes)
						{
							XmlNode xmlNode3 = (XmlNode)obj2;
							list.Add(xmlNode3 as XmlElement);
						}
					}
				}
			}
			catch (Exception)
			{
				throw;
			}
			return list;
		}

		private XmlDocument xmlDoc = null;

		private string xmlPath = "";
	}
}
